module.exports = app => class PortalJsonApi {

    getToken() {
        return app.api.clients.get('bind').getToken(`auth/wanhuhealth-weixin-portal`);
    }

    setToken(token) {
        return app.api.clients.get('bind').setToken(`auth/wanhuhealth-weixin-portal`, token);
    }

	async potentialPatients(patient) {
        return await this.post(`/hd/potentialPatients`, patient)
    }

    async userRegister(param){
		return await this.post(`/patients`, param);
	}

	async perfectInformation(param){
		return await this.post(`/perfectInformation`, param);
    }

  // 找药-添加药品至需求单
	async addDrugToDemand(param) {
		return await this.post(`/patients/${param.patientId}/requisitionForm`, {
			drugId: param.drugId,
			useAmount: param.useAmount,
			frequency: param.frequency,
			amount: param.amount,
		})
	}
	
	// 创建采购药品订单
	async createMedicineOrder(orderId,body) {
		return await this.post(`/orders/${orderId}/pay`, body);
	}

	async createPurchaseVoucher(patientId, query) {
		// query.drugs = JSON.parse(query.drugs)
		return await this.post(`/patients/${patientId}/purchaseVoucher`, query)
	}

	async submitEvaluation(param, patientId) {
		return await this.post(`/patients/${patientId}/medicationEvaluation`, param)
	}

	async submitEnvironmentAssessment(param) {
		param.anamnesisList = JSON.parse(param.anamnesisList)
		param.fdrsCancerList = JSON.parse(param.fdrsCancerList)
		param.secondDegreeRelativeCancerList = JSON.parse(param.secondDegreeRelativeCancerList)
		return await this.post(`/patients/environmentAssessment`, param)
	}
	async activeInsure(insureOrderNo,body) {
		return await this.post(`/insurance_order/insure/${insureOrderNo}`,body);
  } 
  async activeInsureQuestion(insureOrderNo,body) {
		return await this.post(`/v2/insurance_order/insure/${insureOrderNo}`,body);
	} 
}
